Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ipfs metadata provider #5

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Oct 8, 2024

🤖 Linear

Closes GIT-65

Description

  • add metadata package with IpfsProvider

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

Copy link

linear bot commented Oct 8, 2024

Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment :)

Comment on lines +39 to +51
} catch (error: unknown) {
if (error instanceof InvalidContentException) throw error;

if (axios.isAxiosError(error)) {
console.warn(`Failed to fetch from ${url}: ${error.message}`);
} else {
console.error(`Failed to fetch from ${url}: ${error}`);
}
}
}

console.error(`Failed to fetch IPFS data for CID ${ipfsCid} from all gateways.`);
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need a tailored error handling

  • Non existent content should return undefined
  • Network and other errors should retry

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: Could it happen that some content of a cid exist in one gateway and not in other ?

In other words, can we be sure that a cid content doesn't exist in some way ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an interesting question, i have to research since i don't know much about IPFS

regarding the first:

  • non existent returns undefined after checking and failing on all the gateways
  • yeah totally, i left a TODO for working the retry policy

Copy link
Collaborator Author

@0xnigir1 0xnigir1 Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr; it's possible that a CID "exists" on one gateway and not on another if the content hasn't propagated to the node corresponding to that gateway:
https://www.perplexity.ai/search/you-re-an-expert-on-ipfs-and-i-WA60t4oLT46rc1yZySnJkg

Copy link
Collaborator

@0xyaco 0xyaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! After addressing the comments it'd be good to go for me.

throw new InvalidCidException(ipfsCid);
}

for (const gateway of this.gateways) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if latency here is super important but, if it is, have you considered using Promise.any? You'll always be triggering N requests but resolving with the first successful one, instead of calling them sequentially until one of them succeeds.

It could be also helpful to quickly handle non-existant CIDs if, for some reason, you expect working with non-existant CIDs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that could be super helpful but maybe at the same time we exhaust all of the gateways when not needed to 🤔 , like i said to kenji, i will read more about IPFS cuz i know little

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will go back into this analysis when implementing the retry policy, for now we keep this simpler solution for the MVP

@0xnigir1 0xnigir1 merged commit f442eda into dev Oct 9, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/ipfs-metadata-provider branch October 9, 2024 13:51
Copy link
Collaborator

@jahabeebs jahabeebs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Same comments as the others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants